package com.project.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.project.ds.UserMapper;
import com.project.entity.enumcommon.DrEnum;
import com.project.entity.user.User;
import com.project.service.IUserService;

@Service
@Transactional
public class UserServiceImpl implements IUserService{
	
	@Autowired
	private UserMapper userMapper;

	@Override
	public User getById(Long id) {
		return userMapper.findById(User.class, id);
	}

	@Override
	public User getByUserCode(String mobile) {
		User user = new User();
		user.setMobile(mobile);
		user.setDr(DrEnum.DEFAULT.getValue());
		return userMapper.find(user);
	}

	@Override
	public User getByOpenid(String openid) {
		User user = new User();
		user.setWechatOpenid(openid);
		user.setDr(DrEnum.DEFAULT.getValue());
		return userMapper.find(user);
	}

	@Override
	public Long save(User user) {
		userMapper.insert(user);
		return user.getId();
	}

	@Override
	public void update(User user) {
		userMapper.updateSelective(user);
	}

	@Override
	public boolean verifyMobileExists(Long id, String mobile) {
		User user = userMapper.getByMobile(id, mobile);
		if(user!=null)
			return true;
		return false;
	}

}
